<extend name="Base/base"/>

<block name="body">
    <form action="{:U('export')}" method="post" id="database-backup">
    <div class="handler">
        <button type="submit" class="btn btn-blue-o confirm">备份数据</button>
    </div>
    <table class="list">
        <thead>
        <tr>
            <th width="48"><input class="check-all" checked="chedked" type="checkbox" value=""></th>
            <th>表名</th>
            <th width="120">数据量</th>
            <th width="120">数据大小</th>
            <th width="160">创建时间</th>
            <th width="160">备份状态</th>
            <th width="120">操作</th>
        </tr>
        </thead>
        <tbody>
        <volist name="list" id="table">
            <tr>
                <td><input class="ids" type="checkbox" name="tables[]" value="{$table.name}" checked></td>
                <td>{$table.name}</td>
                <td>{$table.rows}</td>
                <td>{$table.data_length|format_bytes}</td>
                <td>{$table.create_time}</td>
                <td class="info">未备份</td>
                <td class="action">
                    <a class="ajax-get confirm" href="{:U('optimize?tables='.$table['name'])}">优化表</a>
                    <a class="ajax-get confirm" href="{:U('repair?tables='.$table['name'])}">修复表</a>
                </td>
            </tr>
        </volist>
        </tbody>
    </table>
    </form>
</block>

<block name="script">
    <script>
        seajs.use(['form','page','tip','admin'],function(){
            $('#database-backup').off('submit').on('submit',function(e){
                e.preventDefault();
                var $form = $(this),action = $form.attr('action'),data = $form.serialize();
                $.post(action,data,function(result){
                    if(result.status == 1) {
                        // 创建一个函数，来递归执行
                        function baking(result) {
                            $.Tip.popup(result.info);
                            var data = result.tab;
                            if(data) {
                                var id = data.id,start = data.start;
                                $.get(action + '?id=' + id + '&start=' + start,function(result){
                                    baking(result);
                                });
                            }
                        }
                        baking(result);
                    }
                    else {
                        $.Tip.popup(result.info);
                    }
                });
            }).attr('ajax-disabled','true');
        });
    </script>
</block>